package com.jinzhi.api.controller.aunt;

import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.JazCoursesOrderDO;
import com.jinzhi.jzweb.service.JazCoursesOrderService;
import com.jinzhi.wxpay.vo.R;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: mcf
 * @CreateTime: 2024/05/17
 * @Description: 订单管理 Controller
 */
@Controller
@RequestMapping("/api/auntOrder")
@Api(value = "阿姨端订单管理", tags = "阿姨端订单管理")
public class AuntOrderController {

    private final JazCoursesOrderService jazCoursesOrderService;

    public AuntOrderController(JazCoursesOrderService jazCoursesOrderService){
        this.jazCoursesOrderService = jazCoursesOrderService;

    }

    @ApiOperation(value = "课程支付", notes = "课程支付")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderName", value = "订单名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "openid", value = "openid", required = true, dataType = "String"),
            @ApiImplicitParam(name = "totalFee", value = "金额", required = true, dataType = "BigDecimal"),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "coursesId", value = "课程id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "addressId", value = "地址id", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazCoursesOrderDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/jsapiPay")
    public Result<?> jsapiPay(@RequestBody JazCoursesOrderDO jazCoursesOrderDTO) {

        //返回小程序支付所需参数
        return  Result.ok(jazCoursesOrderService.jsapiPay(jazCoursesOrderDTO));
    }

    @ApiOperation(value = "阿姨端课程退款", notes = "阿姨端课程退款")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderNo", value = "订单编号", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazCoursesOrderDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/jsapiRefund")
    public Result<?> jsapiRefund(@RequestBody JazCoursesOrderDO jazCoursesOrderDTO) {

        //返回小程序支付所需参数
        return  Result.ok(jazCoursesOrderService.jsapiRefund(jazCoursesOrderDTO));
    }

    @ApiOperation(value = "取消付款（调起微信支付后，再取消支付），保留半个小时订单", notes = "取消付款（调起微信支付后，再取消支付），保留半个小时订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderName", value = "订单名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "openid", value = "openid", required = true, dataType = "String"),
            @ApiImplicitParam(name = "totalFee", value = "金额", required = true, dataType = "BigDecimal"),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "coursesId", value = "课程id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "addressId", value = "地址id", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazCoursesOrderDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/cancelPay")
    public Result<?> cancelPay(@RequestBody JazCoursesOrderDO jazCoursesOrderDO){

        return Result.ok(jazCoursesOrderService.creatOrder(jazCoursesOrderDO));
    }

    @ApiOperation(value = "查询订单列表", notes = "查询订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jazCoursesOrderDO", value = "jazCoursesOrderDO", required = true, dataType = "Integer"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazCoursesOrderDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/selOrderList")
    public Result<?> selOrderList(@RequestBody JazCoursesOrderDO jazCoursesOrderDO){

        return jazCoursesOrderService.selOrderList(jazCoursesOrderDO);
    }


    @ApiOperation(value = "查询订单详情", notes = "查询订单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", required = true, dataType = "Integer"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazCoursesOrderDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/orderDetail")
    public Result<?> orderDetail(Long orderId){

        return jazCoursesOrderService.orderDetail(orderId);
    }


    @ApiOperation(value = "取消订单", notes = "取消订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", required = true, dataType = "Integer"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazCoursesOrderDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/cancelOrder")
    public Result<?> cancelOrder(Long orderId){

        return jazCoursesOrderService.cancelOrder(orderId);
    }


    @ApiOperation(value = "阿姨端将课程订单改为已读", notes = "阿姨端将课程订单改为已读")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderIds", value = "订单id,多个以逗号隔开", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/updateReadStatus")
    public Result<?> updateReadStatus(String orderIds){
        jazCoursesOrderService.updateReadStatus(orderIds);

        return Result.ok();
    }

    @ApiOperation(value = "查询课程订单未读的待付款数量", notes = "查询课程订单未读的待付款数量")
    @ApiImplicitParams({
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = Integer.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/getOrderStatusNum")
    public Result<Integer> getOrderStatusNum(){


        return Result.ok(jazCoursesOrderService.getOrderStatusNum());
    }





}
